<?php
	
	// Session
	session_start();
	
	
	// Integrimi i skedave sistemore
    include('../include/functions.inc.php');
	include('../include/template.class.php');
	
	
	// DB CONNECT
	dbOpen("dielli");
	
	
	// PROJECT
	$PROJECT = setProject();
	
	
	// Ndyshoret primare
	define('TPL','../include/styles/'.$PROJECT['style'].'/dielli/kontakt.html');
	define('FILENAME',basename($_SERVER["PHP_SELF"]));
	
	
	// TMP CLASS
	$tmp = new Template(TPL,$PROJECT['lang']);
	
	
	// SPLASH SCREEN
	if (isset($_GET['splash'])) 
		splash($_GET['splash'], "../dielli/kontakt.php");
	
		
	// MENUES
	$tmp->setContent("CATEGORY",$tmp->menu("category","../dielli"));
	$tmp->setContent("DIELLI",$tmp->menu("dielli",FILENAME));
	$tmp->setContent("FOOTMENU",$tmp->menu("foot"));
	
	$tmp->setContent("NEWS",news("dielli"));
	$tmp->setContent("RANDOM",randomContent("dielli"));
	
	
	$VARS = mysql_fetch_assoc(mysql_query("SELECT title,content FROM contents WHERE cat = 'contact'"));
	$VARS['content'] = nl2br($VARS['content']);
	$tmp->setContent($VARS);
	

	
	if (isset($_POST['name'])) {
		
		if (empty($_POST['name']))
			$ERROR['name'] = "null";
			
		if (empty($_POST['email']))
			$ERROR['email'] = "null";
		elseif (!ereg("^[-A-Za-z0-9_]+[-A-Za-z0-9_.]*[@]{1}[-A-Za-z0-9_]+[-A-Za-z0-9_.]*[.]{1}[A-Za-z]{2,5}$", $_POST['email']))
			$ERROR['email'] = "syntax";
		
		if (empty($_POST['mailbody']))
			$ERROR['mailbody'] = "null";
			
		if (empty($ERROR)) {
			
			$header = "From: ".$_POST['name']." <".$_POST['email'].">\r\n";
			
			// SEND MAIL
			mail($PROJECT['email'], $PROJECT['name'], $_POST['mailbody'], $header);
			
			// Rilexo faqen me porosin per sukses
			header("Location: kontakt.php?splash=sendmail"); 
			exit;
		}
	}
	else {
		
		if (isset($_SESSION['user_id'])) {
			
			$_POST['name'] = $_SESSION['user_name'];
			$_POST['email'] = $_SESSION['user_email'];
		}
	}
	
	// LABELS
	$tmp->setLabels();
	
	
	// Convert POST and ERROR vars in Form
	$tmp->setForm($_POST,$ERROR);
	
	
	// DISPLAY ALL						  
	echo $tmp->vorlage;
?>